package com.eip.zd.controller;

import com.eip.zd.common.Result;
import com.eip.zd.entity.Trade;
import com.eip.zd.service.TradeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/trade")
public class TradeController {
    @Resource
    private TradeService tradeService;

    @GetMapping("/getTradeList")
    public Result getTradeList(@RequestParam(required = false) String keyword) {
        List<Trade> tradeList = tradeService.getTradeList(keyword);
        return Result.success(tradeList);
    }
    @GetMapping("/getTradeListByCustId/{custId}")
    public Result getTradeListByCustId(@PathVariable String custId) {
        List<Trade> tradeList = tradeService.getTradeListByCustId(custId);
        return Result.success(tradeList);
    }
    @GetMapping("/getTradeById/{id}")
    public Result getTradeById(@PathVariable Long id) {
        Trade trade = tradeService.getTradeById(id);
        return Result.success(trade);
    }
    @PostMapping("/add")
    public Result addTrade(@RequestBody Trade trade) {
        tradeService.add(trade);
        return Result.success();
    }
    @PostMapping("/update")
    public Result updateTrade(@RequestBody Trade trade) {
        tradeService.update(trade);
        return Result.success();
    }
    @PostMapping("/remove/{id}")
    public Result removeTrade(@PathVariable Long id) {
        tradeService.remove(id);
        return Result.success();
    }
}
